#pragma once

#include "PointGeometry.h"

class CMapLayerEnvelope
{
public:
	CMapLayerEnvelope()
	{
		m_minX = m_maxX = m_minY = m_maxY = 0;
	}

	inline double width() const
	{
		return m_maxX - m_minX;
	}

	inline double height() const
	{
		return m_maxY - m_minY;
	}

	inline CPointGeometry centerPoint()
	{
		return CPointGeometry((m_minX+m_maxX)/2,(m_minY+m_maxY)/2);
	}

	void unionEnvelope(const CMapLayerEnvelope* const sOther)
	{
		m_minX = min(m_minX,sOther->m_minX);
		m_maxX = max(m_maxX,sOther->m_maxX);
		m_minY = min(m_minY,sOther->m_minY);
		m_maxY = max(m_maxY,sOther->m_maxY);
	}	

	void scaleAtPoint( double scaleFactor, const double& centerX,const double& centerY)
	{
		// scale from the center
		double newWidth = width() * scaleFactor;
		double newHeight = height() * scaleFactor;
		m_minX = centerX - newWidth / 2.0;
		m_maxX = centerX + newWidth / 2.0;
		m_minY = centerY - newHeight / 2.0;
		m_maxY = centerY + newHeight / 2.0;
	}

	void scale(double scaleFactor)
	{
		CPointGeometry centerPt = centerPoint();
		scaleAtPoint(scaleFactor,centerPt.m_x,centerPt.m_y);
	}

	void offset(double offsetX,double offsetY)
	{
		m_minX = m_minX + offsetX;
		m_maxX = m_maxX + offsetX;
		m_minY = m_minY + offsetY;
		m_maxY = m_maxY + offsetY;
	}

	double      m_minX;
	double      m_maxX;
	double      m_minY;
	double      m_maxY;		
};